package com.ahua.mallchat.common.service.impl;

import com.ahua.mallchat.common.domain.enums.user.RoleEnum;
import com.ahua.mallchat.common.service.RoleService;
import com.ahua.mallchat.common.service.cache.UserCache;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private UserCache userCache;

    @Override
    public boolean hasPower(Long uid, RoleEnum roleEnum) {
        //先获取用户的所有权限
        Set<Long> roleIdSet = userCache.getRoleSet(uid);
        //用权限分两个 一个是管理员 那就是啥权限都有 直接true
        return roleIdSet.contains(RoleEnum.ADMIN.getId()) || roleIdSet.contains(roleEnum.getId());
    }
}
